package com.minispider.entity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import com.minispider.util.Db;
import com.minispider.util.HtmlDocument;

public abstract class ParamEntity {
	
	public ArrayList<String> ids = new ArrayList<String>();
	public ArrayList<String> name = new ArrayList<String>();
	
	public String url;
	public String referer;
	public String charsetEncoding;
	
	//xPathExps[0], xPathExps[1]
	public ArrayList<ArrayList<String>> xPathExps = new ArrayList<ArrayList<String>>();
	
	public ArrayList<Object[]> data = new ArrayList<Object[]>();
	
	public Date timeStamp;
	
	public boolean isExpire;
	
	public int maxPage;
	
	public Db db;
	
	public void print() {
		for (int i = 0; i < ids.size(); i++){
			System.out.println("ids ### " + i + " ### " + ids.get(i));
		}
		for (int i = 0; i < name.size(); i++){
			System.out.println("name ### " + i + " ### " + name.get(i));
		}
		System.out.println("url ### " + url);
		System.out.println("charsetEncoding ### " + charsetEncoding);
		System.out.println("timeStamp ### " + timeStamp);
		System.out.println("maxPage ### " + maxPage);

		for (int i = 0; i < xPathExps.size(); i++) {
			if (xPathExps.get(i) != null) {

				for (int j =0; j < xPathExps.get(i).size(); j++) {
					System.out.println("xPathExps ### " + i + " ### " + j + " ### " + xPathExps.get(i).get(j));
					
				}
			}
		}

	}
	
	public void getNextPageHref(HtmlDocument hd) throws Exception {
		
	}
	
	public void process() throws Throwable {

	}
	
	public boolean hasMorePage() {
		
		this.data.clear();
		
		if (this.maxPage >= 0) this.maxPage--;
		
		if (this.maxPage == 0 ||this.isExpire || this.url == null)
		{
			return false;
		}
		
		return true;
	}
	
	//"MM-dd HH:mm"
	public boolean isExpireTime(String tm1, Date timeStamp, String fmt) throws Throwable {
        
		SimpleDateFormat sdf = new SimpleDateFormat(fmt);  

		return sdf.parse(sdf.format(timeStamp)).after(sdf.parse(tm1));
	}
	
}
